package multidraw.tools;

import java.awt.Color;
import java.awt.Point;

import multidraw.model.RectangleShape;
import multidraw.model.Shape;
import multidraw.model.TwoEndBoundaryShape;
import multidraw.model.TwoEndShape;



public class RectangleShapeFactory implements TwoEndShapeFactory {
	public TwoEndShape createShape(Point p1, Point p2, Color c, long id) {
		//construct the rectangle from the points
		double shapeX; //left X, smallest
		double shapeY; //top Y, smallest
		double width;
		double height;
		
		if (p1.getX() <= p2.getX()) {
			shapeX = p1.getX();
			width = p2.getX() - p1.getX() + 1; 
		} else {
			shapeX = p2.getX();
			width = p1.getX() - p2.getX() + 1;
		}
		
		if (p1.getY() <= p2.getY()) {
			shapeY = p1.getY();
			height = p2.getY() - p1.getY() + 1;			
		} else {
			shapeY = p2.getY();
			height = p1.getY() - p2.getY() + 1;
		}
		
		return new RectangleShape(shapeX, shapeY, width, height, c, id);
		//return null;
	}
}
